﻿using Foxit.PDF;
using Foxit.PDF.Imaging;
using Foxit.PDF.IO;
using Foxit.PDF.PageElements;

namespace Sustainalytics.Reporting.Framework
{
    public class BulletOutlook : PageElement
    {
        public float Left { get; set; }
        public float Top { get; set; }
        public float Radius { get; set; }
        public int Value { get; set; }

        private static byte[] _outlookArrowDown;
        private static byte[] _outlookArrowUp;
        private static byte[] _outlookArrowRight;
        public byte[] OutlookArrowDown { get { return _outlookArrowDown; } }
        public byte[] OutlookArrowUp { get { return _outlookArrowUp; } }
        public byte[] OutlookArrowRight { get { return _outlookArrowRight; } }

        static BulletOutlook()
        {
            LoadStaticImages();
        }

        private static void LoadStaticImages()
        {
            if (_outlookArrowDown == null)
                _outlookArrowDown = ImageManager.GetJpgImage(@"Images\outlook_arrow_down.jpg");

            if (_outlookArrowUp == null)
                _outlookArrowUp = ImageManager.GetJpgImage(@"Images\outlook_arrow_up.jpg");

            if (_outlookArrowRight == null)
                _outlookArrowRight = ImageManager.GetJpgImage(@"Images\outlook_arrow_right.jpg");
        }

        private Group Elements()
        {           
            var elements = new Group();

            var scale = Radius*2/480f;

            if (Value == 0)
            {
                elements.Add(new Image(ImageData.GetImage(OutlookArrowRight), Left, Top, scale)
                {
                    Align = Align.Left,
                    VAlign = VAlign.Top
                });
            }
            if (Value == 1)
            {
                elements.Add(new Image(ImageData.GetImage(OutlookArrowUp), Left, Top, scale)
                {
                    Align = Align.Left,
                    VAlign = VAlign.Top
                });
            }
            if (Value == -1)
            {
                elements.Add(new Image(ImageData.GetImage(OutlookArrowDown), Left, Top, scale)
                {
                    Align = Align.Left,
                    VAlign = VAlign.Top
                });
            }

            return elements;
        }

        public override void Draw(PageWriter writer)
        {
            var elements = Elements();

            writer.Write_q_(true);
            elements.Draw(writer);
            writer.Write_Q(true);
        }
    }
}
